﻿Public Class DocBox
    Inherits UserControl

    Private showmenu As Boolean

    Public Shared CloseTabEvent As RoutedEvent = EventManager.RegisterRoutedEvent("CloseTab", RoutingStrategy.Tunnel, GetType(RoutedEventHandler), GetType(DocBox))
    Public Shared CloseAllButTabEvent As RoutedEvent = EventManager.RegisterRoutedEvent("CloseAllButTab", RoutingStrategy.Tunnel, GetType(RoutedEventHandler), GetType(DocBox))
    Public Shared SaveTabEvent As RoutedEvent = EventManager.RegisterRoutedEvent("SaveTab", RoutingStrategy.Tunnel, GetType(RoutedEventHandler), GetType(DocBox))
    Public Shared SaveAsTabEvent As RoutedEvent = EventManager.RegisterRoutedEvent("SaveAsTab", RoutingStrategy.Tunnel, GetType(RoutedEventHandler), GetType(DocBox))

    Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click, CloseMenuItem.Click
        Me.RaiseEvent(New RoutedEventArgs(CloseTabEvent))
    End Sub

    Private Sub SaveMenuItem_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles SaveMenuItem.Click
        Me.RaiseEvent(New RoutedEventArgs(SaveTabEvent))
    End Sub

    Private Sub SaveAsMenuItem_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles SaveAsMenuItem.Click
        Me.RaiseEvent(New RoutedEventArgs(SaveAsTabEvent))
    End Sub

    Public Sub SetMenu(ByVal show As Boolean)
        If show = True Then
            Me.ContextMenu = HeaderMenu
        Else
            Me.ContextMenu = Nothing
        End If
        showmenu = show
    End Sub

    Private Sub DocBox_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
        If Docker.Width > 32 Then
            CloseButton.BringIntoView()
        End If
    End Sub
End Class